package com.credit.jumu.calculator.base;

import android.app.Activity;
import android.content.Context;
import android.support.v4.app.Fragment;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;

import com.credit.jumu.calculator.utils.LogUtils;
import com.umeng.analytics.MobclickAgent;

/**
 * Created by Administrator on 2017/11/22/022.
 */

public class BaseFragment extends Fragment {
	InputMethodManager imm;

	@Override
	public void onResume() {
		super.onResume();
		MobclickAgent.onResume(getContext());
	}

	@Override
	public void onPause() {
		super.onPause();
		MobclickAgent.onPause(getContext());
	}

	public void hideKeyboard(final Context context) {
		Activity activity = (Activity) context;
		InputMethodManager mInputKeyBoard = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
		if (activity.getCurrentFocus() != null) {
			mInputKeyBoard.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
			activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
		}
	}

	protected void hideKeyboard() {
		LogUtils.println("-----------------------111111");
		if (null == imm) {
			imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
		}
		LogUtils.println("-----------------------2222");
		if (imm.isActive() && getActivity().getCurrentFocus() != null) {
			LogUtils.println("-----------------------333");
			if (getActivity().getCurrentFocus().getWindowToken() != null) {
				LogUtils.println("-----------------------444");
				imm.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
			}
		}
	}

}
